package com.liuyu.common.framework.lang.util;

import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;


/**
 * 网络工具
 *
 * @author: liuyu
 * @date: 2023/6/30 11:25
 * @version: 1
 */
public class NetworkUtil {
    private static final String REFERER = "Referer";

    public static String getDomainName(HttpServletRequest request) {
        String referer = request.getHeader(REFERER);
        if (null != referer) {
            return doGetDomain(referer);
        }
        return null;
    }

    private static String doGetDomain(String referer) {
        String domainName = StringUtils.replace(referer, "https://", "").replace("http://", "");
        domainName = StringUtils.substring(domainName, 0, domainName.indexOf("/"));
        return domainName;
    }
}
